package com.atguigui.leetcode1;

import java.util.ArrayList;
import java.util.List;

/**
 * 1238.循环码排列
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/2/23 9:18
 */
public class P1238CircularPermutationInBinaryRepresentation {
    public static void main(String[] args) {
        Solution solution = new P1238CircularPermutationInBinaryRepresentation().new Solution();
        // TO TEST
    }

    class Solution {
        public List<Integer> circularPermutation(int n, int start) {
            List<Integer> ret = new ArrayList<Integer>();
            ret.add(start);
            for (int i = 1; i <= n; i++) {
                int m = ret.size();
                for (int j = m - 1; j >= 0; j--) {
                    ret.add(((ret.get(j) ^ start) | (1 << (i - 1))) ^ start);
                }
            }

            return ret;
        }
    }
}
